<?php
/**
 * CompleXml Framework
 *
 * @category   CompleXml
 * @package    CompleXml_Object
 * @copyright  Copyright (c) 2008 Andrey Kucherenko
 * @license    New BSD License
 * @version    $Id: Abstract.php 8 2008-11-13 14:50:42Z kucherenko.andrey $
 */
abstract class CompleXml_Object_Abstract
{
	/**
	 * Path to objects classes
	 *
	 * @var string
	 */
	static protected $_objects_path = '';
	protected $_actions = array();
	protected $_handlers = array();
	/**
	 * @return string
	 */
	public static function getObjectsPath ()
	{
		return self::objects_path;
	}
	/**
	 * @param string $objects_path
	 */
	public static function setObjectsPath ($objects_path)
	{
		self::$_objects_path = $objects_path;
	}
	/**
	 * @return array
	 */
	public function getHandlers ()
	{
		return $this->_handlers;
	}
	/**
	 * @param CompleXml_Handler_Abstract $handler
	 */
	public function setHandler ($handler)
	{
		$this->_handlers[] = $handler;
	}
	/**
	 * @return array
	 */
	public function getActions ()
	{
		return $this->_actions;
	}
	/**
	 * @param string $action
	 */
	public function addAction ($action)
	{
		if (is_string($action)){
			$this->_actions[$action] = true;
		}
	}
	public function deleteAction ($name)
	{
		if (! empty($this->_actions[$name])) {
			unset($this->_actions[$name]);
		}
	}
	public function __set ($name, $value)
	{
		if ($value instanceof CompleXml_Handler_Abstract) {
			$method = 'get'.$name;
			if (method_exists($value,$method )){
				$this->$name = $value->$method();
				return true;
			}
		}
		require_once 'CompleXml/Object/Exception.php';
		throw new CompleXml_Object_Exception('Can\'t sets attribute of class' );
	}

	protected function _redirect($class_file)
	{
		if (!file_exists(self::$_objects_path.DIRECTORY_SEPARATOR.$class_file.'.php')){
			require_once 'CompleXml/Object/Exception.php';
			throw new CompleXml_Object_Exception('Object class not found');
		}
		require_once self::$_objects_path.DIRECTORY_SEPARATOR.$class_file.'.php';
		die();
	}

	abstract public function __construct ();
}